
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>

        var person1 = {"name":"张三",age:20,'gender':true}; // person1是json对象。
        //获取person1对象中所有的键和值
        //for in 循环
        /*for (var key in person1) {
            //这样的获取方式不行。因为相当于 person1."name"
            //alert(key+":"+person1.key);
            alert(key+":"+person1[key]);
        }*/

        var ps = [
            {"name":"张三","age":21,"gender":true},
            {"name":"李四","age":22,"gender":false},
            {"name":"王五","age":23,"gender":false}
        ];
        //获取ps中的所有值
        for (var i = 0; i < ps.length; i++) {
            var p = ps[i];
            for (var key in p){
                alert(key+":"+p[key]);
            }
        }

    </script>
</head>
<body>

</body>
</html>

